package com.example.cartmanage.chewei.adapter

import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.cartmanage.R
import com.example.cartmanage.chewei.entity.CheLiangEntity
class CheLiangAdapter(private val items:MutableList<CheLiangEntity>) : RecyclerView.Adapter<ItemViewHolder>() {

    fun updateData(newItems: CheLiangEntity) {
        items.clear()
        items.addAll(listOf(newItems))
        notifyDataSetChanged()
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_cheliang,parent,false)
        return ItemViewHolder(view)
    }

    override fun getItemCount(): Int {
        Log.d("CheLiangAdapter", "数据量: ${items.size}")
        return items.size
    }

    override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
        Log.d("CheLiangAdapter", "绑定位置: $position, 数据: ${items[position]}")
        holder.bind(items[position])

    }
}
class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    private val titleTextView: TextView = itemView.findViewById(R.id.tv01)
    private val descTextView: TextView = itemView.findViewById(R.id.tv02)
    private val tv3: TextView = itemView.findViewById(R.id.tv03)
    private val tv4: TextView = itemView.findViewById(R.id.tv04)
    private val tv5: TextView = itemView.findViewById(R.id.tv05)
    private val btn01: Button = itemView.findViewById(R.id.btn01)
    private val btn02: Button = itemView.findViewById(R.id.btn02)


    fun bind(item: CheLiangEntity) {
        titleTextView.text = item.licensePlate
        descTextView.text = item.ownerName
        tv3.text = "入场10：15"
        tv4.text = "已停2小时30分"
        tv5.text = "A区-12号"
        btn01.setOnClickListener {
          ARouter.getInstance().build("/cartmanage/EditParkActivity").withInt("parkId",item.id).navigation()
        }
        btn02.setOnClickListener {
            ToastUtils.showShort("btn02")
        }
    }
}